package com.rokyinfo.generator;

/**
 * Created by yuanzhijian on 2017/2/4.
 */
public class IMEIGenerator {

    /**
     * 生产IMEI
     * @param lastImei
     * @param j
     * @return
     */
    public static String generateIMEI(String lastImei,int j) {

        String imei = lastImei.substring(0, lastImei.length() - 1);
        long imeiLong = Long.parseLong(imei);
        String currentImei = String.valueOf(imeiLong + j + 1);

        int chk = 0;
        for (int i = 0; i < 7; i++) {

            int ch1 = Integer.parseInt(currentImei.substring(i * 2 + 1,
                    i * 2 + 1 + 1));
            int ch2 = Integer.parseInt(currentImei.substring(i * 2, i * 2 + 1));

            chk += ch1 * 2 / 10;
            chk += ch1 * 2 % 10;
            chk += ch2;
        }

        chk = chk % 10;
        if (chk != 0)
            chk = 10 - chk;

        return currentImei + String.valueOf(chk);
    }

}
